package com.joysuch.wwyt.workflow.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.joysuch.wwyt.workflow.entity.dto.SummaryInquiryTaskDto;
import com.joysuch.wwyt.workflow.entity.dto.WorkflowStatisticDto;
import com.joysuch.wwyt.workflow.entity.dto.WorkflowTaskDto;
import org.springframework.data.repository.query.Param;

import java.util.Date;
import java.util.List;
import java.util.Set;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author jingwk
 * @since 2021-04-01
 */
public interface WorkflowTaskMapper extends BaseMapper<WorkflowTaskDto> {

    /**
     * 分页获待办任务
     * @param page
     * @param userId
     * @param roleIds
     * @param departId
     * @param jobId
     * @param processIds
     * @param searchSql
     * @return
     */
    IPage<WorkflowTaskDto> queryToDoTaskPaging(Page<WorkflowTaskDto> page, Long userId, List<Long> roleIds, Long departId, Long jobId,List<Long> processIds,Long typeId,String companyCode,Long tenantId,Set<Long> departIds, String searchSql);

    /**
     * 查询待办数量
     * @param userId
     * @param roleIds
     * @param departId
     * @param jobId
     * @param processIds
     * @param typeId
     * @param companyCode
     * @param tenantId
     * @param searchSql
     * @return
     */
    long queryToDoTaskCount(Long userId, List<Long> roleIds, Long departId, Long jobId,List<Long> processIds,Long typeId,String companyCode,Long tenantId,Set<Long> departIds, String searchSql);

    /**
     * 查询已办列表
     * @param page
     * @param userId
     * @param processIds
     * @param searchSql
     * @return
     */
    IPage<WorkflowTaskDto> queryProcessedTaskPaging(Page<WorkflowTaskDto> page, Long userId,List<Long> processIds,Long typeId, String searchSql);

    /**
     * 查询已办数量
     * @param userId
     * @param processIds
     * @param searchSql
     * @return
     */
    long queryProcessedTaskCount(Long userId,List<Long> processIds,Long typeId, String searchSql);

    /**
     * 查询我发起的数量
     * @param userId
     * @param processIds
     * @param searchSql
     * @return
     */
    long queryProposerTaskCount(Long userId,List<Long> processIds,Long typeId, String searchSql);

    /**
     * 查询我发起的列表
     * @param page
     * @param userId
     * @param processIds
     * @param searchSql
     * @return
     */
    IPage<WorkflowTaskDto> queryProposerTaskPaging(Page<WorkflowTaskDto> page, Long userId,List<Long> processIds,Long typeId, String searchSql);

    /**
     * 查询已完成的列表
     * @param page
     * @param userId
     * @param processIds
     * @param searchSql
     * @return
     */
    IPage<WorkflowTaskDto> queryCompletedTaskPaging(Page<WorkflowTaskDto> page, Long userId,List<Long> processIds,Long typeId, String searchSql);

    /**
     * 查询已完成的数量
     * @param userId
     * @param processIds
     * @param searchSql
     * @return
     */
    long queryCompletedTaskCount(Long userId,List<Long> processIds,Long typeId, String searchSql);


    /**
     * 查询已完成的列表
     * @param page
     * @param processIds
     * @param searchSql
     * @param departIds
     * @param orderBySql
     * @return
     */
    IPage<WorkflowTaskDto> queryAllTaskPaging(Page<WorkflowTaskDto> page, List<Long> processIds, Long typeId, String searchSql, Set<Long> departIds, String companyCode, Long tenantId, String orderBySql);


    /***
     *  查询已完成的列表(运行机制效果)
     * @param page
     * @param processIds
     * @param typeId
     * @param searchSql
     * @param departIds
     * @param companyCode
     * @param tenantId
     * @param orderBySql
     * @param departName
     * @return
     */
    IPage<WorkflowTaskDto> queryNewAllTaskPaging(Page<WorkflowTaskDto> page, List<Long> processIds, Long typeId, String searchSql, Set<Long> departIds, String companyCode,
                                                 Long tenantId, String orderBySql, String departName, String departUnitName, String reportName, Date startTime, Date endTime);

    /**
     * 查询已完成的数量
     * @param processIds
     * @param searchSql
     * @param departIds
     * @return
     */
    long queryAllTaskCount(List<Long> processIds, Long typeId, String searchSql, Set<Long> departIds,String companyCode,Long tenantId);

    long queryAllNewTaskCount(List<Long> processIds, Long typeId, String searchSql, Set<Long> departIds,String companyCode,
                              Long tenantId,String departName,String departUnitName, String reportName, Date startTime, Date endTime);

    /**
     * 草稿列表
     * @param page
     * @param userId
     * @param processIds
     * @param typeId
     * @param searchSql
     * @return
     */
    IPage<WorkflowTaskDto> queryDraftTaskPaging(Page<WorkflowTaskDto> page, Long userId, List<Long> processIds, Long typeId, String searchSql);

    /**
     * 草稿数量
     * @param userId
     * @param processIds
     * @param typeId
     * @param searchSql
     * @return
     */
    long queryDraftTaskCount(Long userId, List<Long> processIds, Long typeId, String searchSql);


    /**
     * 汇总查询列表
     * @param page
     * @param processIds
     * @param searchSql
     * @param departIds
     * @return
     */
    IPage<SummaryInquiryTaskDto> querySummaryInquiryTaskPaging(Page<SummaryInquiryTaskDto> page, List<Long> processIds, String searchSql, Set<Long> departIds, String orgCode, Long tenentId);

    /**
     * 汇总查询数量
     * @param processIds
     * @param searchSql
     * @param departIds
     * @return
     */
    long querySummaryInquiryTaskCount(List<Long> processIds, String searchSql, Set<Long> departIds, String orgCode, Long tenentId);

    /**
     * 获取关联作业列表
     * @param page
     * @param processIds
     * @param typeId
     * @param searchSql
     * @param companyCode
     * @param tenantId
     * @return
     */
    IPage<WorkflowTaskDto> queryTaskSimpleListPaging(Page<WorkflowTaskDto> page, List<Long> processIds, Long typeId, String searchSql, String companyCode, Long tenantId, Integer finishFlag);

    /**
     * 取关联作业列表数量
     * @param processIds
     * @param typeId
     * @param searchSql
     * @param companyCode
     * @param tenantId
     * @return
     */
    long queryTaskSimpleListCount(List<Long> processIds, Long typeId, String searchSql, String companyCode, Long tenantId, Integer finishFlag);


    int countByProcessIdAndSyncStatus(Long processId, int syncStatus);

    List<WorkflowStatisticDto> queryFormDataByProcessIdAndSyncStatus(Long processId, int syncStatus, int batchSize);

    int updateSyncStatus(@Param("id") Long id,@Param("syncStatus") int syncStatus);
}
